//
//  LRUserAccount.swift
//  LRWeibo
//
//  Created by admin on 15/9/24.
//  Copyright © 2015年 懒人. All rights reserved.
//  用户信息

import UIKit

class LRUserAccount: NSObject,NSCoding {
    
     // MARK: - 单利
    static let sharedUserAccount = LRUserAccount(dict: ["dd":"dd"])
     // MARK: - 成员变量
    /// 授权码
    var access_token: String?
    /// 有效期
    var expires_in: NSTimeInterval = 0 {
        didSet{
            expires_date = NSDate(timeIntervalSinceNow: expires_in)
        }
    }
    /// uid
    var uid: String?
    /// 有效期转换
    var expires_date: NSDate?
    /// 用户昵称
    var screen_name: String?
    /// 头像地址
    var avatar_large: String?
     // MARK: - 初始化
    init(dict: [String: AnyObject]) {
        super.init()
        self.setValuesForKeysWithDictionary(dict)
    }
    
    // 不存在的key
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        //
    }
    
     // MARK: - 解裆
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        expires_date = aDecoder.decodeObjectForKey("expires_date") as? NSDate
        uid = aDecoder.decodeObjectForKey("uid") as? String
        screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
        avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
    }
    
    // 归档
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeObject(expires_date, forKey: "expires_date")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(screen_name, forKey: "screen_name")
        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
    }
}
